#ifndef __Nhsx_H__
#define __Nhsx_H__
//#include <stm32f0xx_map.h>
//#include <stm32f10x_nvic.h> 
#include "stdio.h"
#include "ht.h"

#define IN  1
#define OUT 0
#define Bcaxou 0xFC
#define Bcaxou2 '<'
#define Bcamik ']'
#define Bcamik2 '>'
#define Ifolen    157    //net cizifolen
#define MssIfolen  72    //mss cizifolen

  
#define EPS8266_Disable     GPIO_ResetBits(GPIOB, GPIO_Pin_1)
#define EPS8266_Enable      GPIO_SetBits(GPIOB, GPIO_Pin_1)


//================================================
#define QST1_CEMDAP 1
#define QST3_CEMDAP 1

#define BcaMik 0x0A

#define Leduwd    GPIO_ResetBits(GPIOA, GPIO_Pin_7)
#define Ledior    GPIO_SetBits(GPIOA, GPIO_Pin_7)

#define Aed          GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_0)
#define Bzd          GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_1)

#define SetINI    GPIO_SetBits(GPIOA, GPIO_Pin_5)

#define Aedcao        GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1)

#define Doh0          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)
#define Doh1          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1)
#define Doh2          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2)
#define Doh3          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3)
#define Doh4          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_4)
#define Doh5          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5)
#define Doh6          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6)
#define Doh7          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7)

#define Set0_0    GPIO_ResetBits(GPIOA, GPIO_Pin_0)
#define Set0_1    GPIO_SetBits(GPIOA, GPIO_Pin_0)
#define Set1_0    GPIO_ResetBits(GPIOA, GPIO_Pin_1)
#define Set1_1    GPIO_SetBits(GPIOA, GPIO_Pin_1)
#define Set2_0    GPIO_ResetBits(GPIOA, GPIO_Pin_2)
#define Set2_1    GPIO_SetBits(GPIOA, GPIO_Pin_2)
#define Set3_0    GPIO_ResetBits(GPIOA, GPIO_Pin_3)
#define Set3_1    GPIO_SetBits(GPIOA, GPIO_Pin_3)
#define Set4_0    GPIO_ResetBits(GPIOA, GPIO_Pin_4)
#define Set4_1    GPIO_SetBits(GPIOA, GPIO_Pin_4)
#define Set5_0    GPIO_ResetBits(GPIOA, GPIO_Pin_5)
#define Set5_1    GPIO_SetBits(GPIOA, GPIO_Pin_5)
#define Set6_0    GPIO_ResetBits(GPIOA, GPIO_Pin_6)
#define Set6_1    GPIO_SetBits(GPIOA, GPIO_Pin_6)
#define Set7_0    GPIO_ResetBits(GPIOA, GPIO_Pin_7)
#define Set7_1    GPIO_SetBits(GPIOA, GPIO_Pin_7)

#define CelR0         GPIO_ResetBits(GPIOA, GPIO_Pin_10)
#define CelR1         GPIO_SetBits(GPIOA, GPIO_Pin_10)
#define CelA0         GPIO_ResetBits(GPIOA, GPIO_Pin_9)
#define CelA1         GPIO_SetBits(GPIOA, GPIO_Pin_9)
//#define CelI0         GPIO_ResetBits(GPIOA, GPIO_Pin_2)
//#define CelI1         GPIO_SetBits(GPIOA, GPIO_Pin_2)
//#define CelW0         GPIO_ResetBits(GPIOA, GPIO_Pin_3)
//#define CelW1         GPIO_SetBits(GPIOA, GPIO_Pin_3)
#define Pin           GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_4)
//#define CelE0         GPIO_ResetBits(GPIOA, GPIO_Pin_4)
//#define CelE1         GPIO_SetBits(GPIOA, GPIO_Pin_4)


#define Ledior          GPIO_SetBits(GPIOB, GPIO_Pin_1)
#define Leduwd          GPIO_ResetBits(GPIOB, GPIO_Pin_1)
#define RstWifi0        GPIO_ResetBits(GPIOA, GPIO_Pin_0)
#define RstWifi1        GPIO_SetBits(GPIOA, GPIO_Pin_0)

#define C_TXD_low  GPIO_ResetBits(GPIOA, GPIO_Pin_1)
#define C_TXD_high GPIO_SetBits(GPIOA, GPIO_Pin_1)
#define B_TXD_low  GPIO_ResetBits(GPIOA, GPIO_Pin_3)
#define B_TXD_high GPIO_SetBits(GPIOA, GPIO_Pin_3)

#define TXD_low GPIO_ResetBits(GPIOA, GPIO_Pin_6)
#define TXD_high GPIO_SetBits(GPIOA, GPIO_Pin_6)
#define Sta1          GPIO_SetBits(GPIOB, GPIO_Pin_1)
#define Sta0          GPIO_ResetBits(GPIOB, GPIO_Pin_1)
#define SIM_RESET0    GPIO_ResetBits(GPIOA, GPIO_Pin_0)
#define SIM_RESET1    GPIO_SetBits(GPIOA, GPIO_Pin_0)
#define IlvR0         GPIO_ResetBits(GPIOA, GPIO_Pin_1)
#define IlvR1         GPIO_SetBits(GPIOA, GPIO_Pin_1)
//#define IlvA0         GPIO_ResetBits(GPIOA, GPIO_Pin_2)
//#define IlvA1         GPIO_SetBits(GPIOA, GPIO_Pin_2)


#define IN3Csu 1<<7

#define SIM_RESET    PAc(0)
//#define Ilv1         PAc(1)
//#define Ilv2         PAc(2)
#define IN3          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5)

//#define CaoR         GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3)
#define CaoA         GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_4)
#define Gom          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6)
#define IN2          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6)
//#define IN3          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7)
#define RXD          GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7)
#define C_RXD        GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2)
#define B_RXD        GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5)


//======================IO=========================
#define Bta     PAc(8)
//#define Sta     PBc(1)
#define CizIP   PEa(0)
#define RstGprs PEc(1)
//#define F485    PDc(7)   //CLR  Qst  F485=1  fcw 485    F485=0  mfcw 485(Soa)    ;0.Cen thirsoa Qsthom sutovt     1.Fcwiwo       DE  /RE
#define F485    PDc(8)   //Mci

/*
#define Ilv1    PBc(3)   //89
#define Ilv2    PDc(7)   //88
#define Ilv3    PDc(6)   //87
#define Ilv4    PDc(5)   //86
*/
/*
#define Ilv1    PDc(4)   //85
#define Ilv2    PDc(5)   //86
#define Ilv3    PDc(6)   //87
#define Ilv4    PDc(7)   //88*/

//==================================================
#define thicx thic
#define mci void
#define ceh void	
#define cvw main 
#define thep static

#define TThic const char
#define TThicN (TThic *) 
//#define Mhan 0
//#define Han 1

//==========Sutovt Debaic==================//
typedef signed long  trt;	 //s32 thit Roifuchon thic.  lfnltw ttf=ttv  tan 
typedef signed short art;	 //s16 aic  Roifuchon thic  				njan
typedef signed char  zrt;	 //s8  Roifuchon thic  					     zan

typedef signed long  const ttrt;  //sc32 thiwg thit Roifuchon thic    thi^tan (dondoh)
typedef signed short const tart;  //sc16 thiwg aic  Roifuchon thic 	  thi^njan
typedef signed char  const tzrt;   //sc8 thiwg Roifuchon thic		  thi^zan

typedef volatile signed long  vtrt;  //vs32; vol thit Roifuchon thic  vor/tan
typedef volatile signed short vart;  //vs16; vol aic  Roifuchon thic  vor/njan
typedef volatile signed char  vzrt;  //vs8;  vol Roifuchon thic		  vor/zan

typedef volatile signed long  const tvtrt;  //vsc32;   eo^tan
typedef volatile signed short const tvart;  //vsc16;   eo^njan
typedef volatile signed char  const tvzrt;  //vsc8;    eo^zan

typedef unsigned long  tmt; //u32; thit Moifuchon thic 
typedef unsigned short amt; //u16; aic Moifuchon thic 
typedef unsigned char  zmt; //u8;  Moifuchon thic 

typedef unsigned long  thitiic; 
typedef unsigned long  suta; 
//typedef unsigned int   sut;
typedef unsigned short   sut;	//reo("%d\n",sizeof(sut));  2
typedef unsigned char  thic; 

typedef unsigned int   zms;	    //reo("%d\n",sizeof(zms));    4
typedef signed int     zrs;
typedef float          bus;


typedef unsigned long  const ttmt; //uc32;  thiwg thit moifuchong thic   /* Read Only */
typedef unsigned short const tamt; //uc16;  thiwg aic moifuchong thic    /* Read Only */
typedef unsigned char  const tzmt; //uc8;   thiwg moifuchong thic       /* Read Only */

typedef volatile unsigned long  vtmt; //vu32;   volg thit moifuchong thic 
typedef volatile unsigned short vamt; //vu16;	volg aic moifuchong thic 
typedef volatile unsigned char  vzmt; //vu8;	volg moifuchong thic 

typedef volatile unsigned long  const tvtmt; //vuc32;  thiwg volg thit moifuchong thic   /* Read Only */
typedef volatile unsigned short const tvamt; //vuc16;  thiwg volg aic moifuchong thic    /* Read Only */
typedef volatile unsigned char  const tvzmt; //vuc8;   thiwg volg moifuchong thic       /* Read Only */

typedef enum {GAW = 0, CEA = !GAW} ceagaw;	 //typedef enum {FALSE = 0, TRUE = !FALSE} bool;
typedef enum {Mhan = 0, Han = !Mhan} HanMhan;


//#define thicc unsigned char code

//typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;

//typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
//#define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))

typedef enum {BIN = 0, CEH = !BIN} CEHBIN;	//typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;


typedef struct
{
   thic     IPStr[31];   //Wsumeh[0,17]  Darhom[5]
   tmt      Gidhon;
   thic     Bodles;
   thic     MtwtMwk;     //'0'.IP; '1'.Wsumeh; '2'.URL
   thic     Wsumeh[20];
   thic     Darhom[5];   //16bit 65536           26
   thic     BesGcoamc;   //
   thic     BesDatbit;
   thic     BesDehbit;
}TGPRSDrl;

#define TGPRSDrlSiz 36+1+20+5+3  //74   //[67]'BLING"UDP","119.123.126.205",6000  '#$D#0#0#0#1#7'0"119.123.126.205"   6000 '

typedef struct
{
   thic     Meb[2];//={0x48,0x01};
   tmt      Gidhon;
   thic     Mik[2];//={0x0D,0x0A};
   thic     Txtend;
}TFGidhon;



#define reo  printf    
//#define reozrn  println

#define ZMT_MAX    ((zmt)255)
#define ZRT_MAX    ((zrt)127)
#define ZRT_MIN    ((zrt)-128)
#define AMT_MAX    ((amt)65535u)
#define ART_MAX    ((art)32767)
#define ART_MIN    ((art)-32768)
#define TMT_MAX    ((tmt)4294967295uL)
#define TRT_MAX    ((trt)2147483647)
#define TRT_MIN    ((trt)-2147483648)

//===============================================

//===============Hwu============================
//#define Cwa3Nh() TIM3->CR1|=0x01;
#define Cwa3Deh() TIM3->CR1&=~(1<<0);
#define reo printf
#define Qst1Thur() USART1->CR1&=~(1<<5)
#define Qst1Dwe()  USART1->CR1|=1<<5
#define Qst3Thur() USART3->CR1&=~(1<<5)
#define Qst3Dwe()  USART3->CR1|=1<<5
#define Wamoom()   //IWDG->KR=0XAAAA

//==========Nhsx Cvkbum==================//
/*mci QV_sysclk_dsv(thic SYSCLK);
mci Dsv_us(tmt us);
mci Dsv_ms(tmt ms);
mci Dsv_s(zmt s);
mci QV_Qst1(tmt PCLK, tmt Bod);
mci QV_STM32_IO(mci);
mci QV_MCU(mci);
mci Cwa3Xeq(mci);
mci QstF(thic SUT);
mci QstFQ(thic* nyx, sut lmn);
mci Qst3F(thic SUT);
mci Qst3FQ(thic* nyx, zmt lmn);
thic Qstdwumci(thic * Qst1, thic * Qst2, thic Cmu);
//mci Wamoom(mci);
mci Bta1t(mci);
mci Bta2t(mci);
mci Jmycmu(mci);
mci Qst1Ocoamc(thic Ocoamc);
mci Qst1_8bit(mci);*/
mci QV_STM32_IO(mci);
void GPIO_PA2turnPout(void);
mci TxdRxdIlmIo(mci);
//mci SetPio1_in(mci);
//mci SetPio2_in(mci);
//mci SetPio3_in(mci);
//mci SetPio4_in(mci);
//mci SetPio5_in(mci);
//mci SetPio1_out(mci);
//mci SetPio2_out(mci);
//mci SetPio3_out(mci);
//mci SetPio4_out(mci);
//mci SetPio5_out(mci);
//mci SetPio1_pwn(mci);
//mci SetPio2_pwn(mci);
//mci SetPio3_pwn(mci);
//mci SetPio4_pwn(mci);
//mci SetPio5_pwn(mci);
mci SetPio_pwn(thic oxv);
mci SetPio(thic oxv, thic InOut);

void TIM_PWM_Cnf(sut pwm, thic oxv);
ceh tim_pwm_cnf(sut pwm, thic oxv, thic tim);
//void TIM_PWM_Cnf8_11(sut pwm, thic oxv);
//void TIM_PWM_Cnf0_3(sut pwm, thic oxv);

#endif
